package com.fenghongzhang.module_play.service

import android.content.ComponentName
import android.content.Intent
import android.content.ServiceConnection
import android.os.Bundle
import android.os.IBinder
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.fenghongzhang.module_play.R

class PlayActivity : AppCompatActivity() {

    private val mServiceConnection = object : ServiceConnection {
        override fun onServiceConnected(name: ComponentName?, service: IBinder?) {
           //val binder =   service as MyService.MyBinder


        }

        override fun onServiceDisconnected(name: ComponentName?) {

        }

    }
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(R.layout.activity_play)
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
            insets
        }
        val intent = Intent(this, MyService::class.java) //下载
        startService(intent)
      //  stopService(intent)


        bindService(intent, mServiceConnection, BIND_AUTO_CREATE)
    }



    override fun onDestroy() {
        super.onDestroy()
        unbindService(mServiceConnection)
    }
}